require "test/unit"
require 'builder'
require "hpricot"
require "gtk2"

require "../main/TaskXMLParser"
require "../main/TaskXMLBuilder"
require "../main/model/Task"

class SaveLoadTest < Test::Unit::TestCase
	
	def setup
    task1 = Task.new
    task1.id = "123dsfcsdft345"
    task1.name ="设计"
    task1.startTime = "2008-1-1"
    task1.deadline = "2008-1-9"
    task1.status = "dead"
    task1.comment="架构设计"
    
    task2 = Task.new
    task2.id = "223dsfcsdft345"
    task2.name ="coding"
    task2.startTime = "2008-9-5"
    task2.deadline = "2008-9-12"
    task2.status = "ongoing"
    
    task3 = Task.new
    task3.id = "323dsfcsdft345"
    task3.name ="refactoring"
    task3.startTime = "2008-9-13"
    task3.deadline = "2008-9-15"
    task3.status = "plan"
    
    @tasks  = Array.new
    @tasks << task1
    @tasks << task2
    @tasks << task3
    
		folder = "中文"
		filename = "任务保存文件.xml"
		
		@file = folder+"/"+filename
		@utf8_folder = GLib::Win32.locale_filename_from_utf8(folder)
		@utf8_file = GLib::Win32.locale_filename_from_utf8(@file)
		
	end
	
	def testSaveAndLoadTasks
		
		Dir::mkdir @utf8_folder
		TaskXMLBuilder.new.write2XML @tasks,@utf8_file
		
		newTasks = Array.new
		TaskXMLParser.new.getTasksFromFile @utf8_file,newTasks
		
		assert_equal 3,newTasks.length
		
	end
	
	def teardown
		if FileTest::exists?(@utf8_file)
			File.delete @utf8_file
		end
		
		if FileTest::exists?(@utf8_folder)
			Dir::rmdir @utf8_folder
		end
	end
	
end